//var urlcore = "http://app.jiagangwangluo.com:/api";
//var urlcore = "/api";
var urlcore = "http://127.0.0.1:8080";
//var urlcore = "http://192.168.2.144:8081";
//var urlcore = "http://127.0.0.1:8081";
//var urlcore = 'http://www.jumeiclub.com/interface/api/json';

var pageSize = 8;
//从url中获取参数值
function getvl(name) {
    var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
    if (reg.test(location.href.trim())) return unescape(RegExp.$2.replace(/\+/g, " "));
    return "";
};

//设置全局ajax
$.ajaxSetup({
    xhrFields: {
    	withCredentials: true
	}
});




/**
 * 移除Html代码
 */
function removeStrHtml(obj){
	$(obj).parent().remove();
}



//创建
var gc = gc || {};
gc.ajax = function(options){//options =  {url:'',method:'',data:'',callback:'',async:''}
    //默认参数
    options.url = options.url || '',
    options.method = options.method || 'get',
    options.data = options.data || '',
    options.callback = options.callback || '',
    options.async = options.async || true;
    //get请求-拼接url
    if(options.method.toLowerCase() == 'get'){
        if(typeof options.data == 'object'){
            options.data = [];
            for (var k in options.data){
                options.data.push(k+'='+options.data[k]);
                options.data.join('&');
            }
        }
        options.url += (options.url.indexOf('?' == -1) ? '?' : '') + options.data;
    }
    //post请求-转换字符串
    if(options.method.toLowerCase() == 'post'){
        if(typeof options.data == 'object'){
            var arrs = [];
            for (var k in options.data){
                arrs.push(k+'='+options.data[k]);
            }
            options.data = arrs.join('&');
        }
    }
    //创建发送请求
    var xhr = window.XMLHttpRequest ?  new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); //兼容ie
    xhr.open(options.method,options.url,options.async);
    if(options.method == 'post'){
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xhr.send(options.data);
    }else{
        xhr.send(null);
    }
    //异步请求
    if(options.async == true){
        xhr.onreadystatechange = function(){
          if(xhr.readyState == 4){
              callcall();
          }
        }
    }
    // xhr.abort(); // 取消异步请求
    //同步请求
    if(options.async == false){
        callcall();
    }
    //返回状态判断
    function callcall(){
        if(xhr.status == 200){
            options.callback(xhr.responseText);
        }else{
            options.callback('error:' + xhr.status + xhr.statusText);
        }
    }
};
